﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MODEL;

namespace DAL
{
    public class StuCardService
    {
        /// <summary>
        /// 查询学生信息
        /// </summary>
        /// <returns></returns>
        public static DataTable ChaXunStudent1()
        {
            string sql = "select*from StuCard";

            DataTable dt = SqlHelper.QueryMethod(sql);
            return dt;

        }

        /// <summary>
        /// 学生登录
        /// </summary>
        /// <returns></returns>
        public static int ChaXunStudentPwd(StuCard stuCard)
        {
            string sql = "select*from StuCard where StuName =@StuName and StuId=@StuId";

            SqlParameter[] sp =
            {
                 new SqlParameter("@StuId",stuCard.StuId),
                 new SqlParameter( "@StuName",stuCard.StuName),
            };
            DataTable dt = SqlHelper.QueryMethod(sql,sp);
            int num = dt.Rows.Count;
            return num;

        }
        /// <summary>
        /// 添加学生信息的方法
        /// </summary>
        /// <param name="stuInfo"></param>
        /// <returns></returns>
        public static int Add(StuCard stuCard)
        {
            try
            {
                string sql = "insert into StuCard values (@StuId, @StuName,@StuSex, @StuCardId)";
                SqlParameter[] sp =
              {
                 new SqlParameter("@StuId",stuCard.StuId),
                 new SqlParameter( "@StuName",stuCard.StuName),
                 new SqlParameter( "@StuSex",stuCard.StuSex),
                 new SqlParameter( "@StuCardId",stuCard.StuCardId)
            };

                int num = SqlHelper.NonQueryMethod(sql, sp);
                return num;
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }
        /// <summary>
        /// 修改学生信息
        /// </summary>
        /// <param name="stuCard"></param>
        /// <returns></returns>
        public static int Update(StuCard stuCard)
        {
            try
            {
                string sql = "update StuCard set StuName=@StuName,StuCardId=@StuCardId,StuSex=@StuSex where StuId=@StuId";
                SqlParameter[] sp =
              {
                 new SqlParameter("@StuId",stuCard.StuId),
                 new SqlParameter( "@StuName",stuCard.StuName),
                 new SqlParameter( "@StuSex",stuCard.StuSex),
                 new SqlParameter( "@StuCardId",stuCard.StuCardId),
            };

                int num = SqlHelper.NonQueryMethod(sql, sp);
                return num;
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }
        /// <summary>
        /// 带条件的查询学生信息
        /// </summary>
        /// <param name="stuCard"></param>
        /// <returns></returns>
        public static DataTable ChaXunStudent2(StuCard stuCard)
        {
            SqlParameter[] sp =
            {
            new SqlParameter("@StuName",stuCard.StuName),
            new SqlParameter("@StuId",stuCard.StuName)
            };
        DataTable dt = SqlHelper.CunChu("proc_ChaXun",sp,CommandType.StoredProcedure);

            return dt;
        }
        /// <summary>
        /// 删除学生信息的方法
        /// </summary>
        /// <param name="stuCard"></param>
        /// <returns></returns>
        public static int StuCardDelete(StuCard stuCard)
        {
            string sql = "delete from StuCard where StuId=@StuId";
            SqlParameter[] sp =
            {
             new SqlParameter("@StuId",stuCard.StuId)
            };
            int num = SqlHelper.NonQueryMethod(sql,sp);
            return num;
        }
    }
}
